<template>
  <a-card :bordered="false">
      <!-- 查询区域 -->
    <div class="table-page-search-wrappe">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="单据来源">
              <j-dict-select-tag placeholder="请选择单据来源" @input="handleDocumentSource" v-model="queryParam.permissionType" dictCode="permission_type"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24" v-show="queryParam.permissionType == 3">
            <a-form-item label="选择部门">
              <J-select-multiple
                placeholder="请选择选择部门"
                :options="getDepartName"
                showId="id"
                v-model="queryParam.deptIds"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24" v-show="queryParam.permissionType == 4">
            <a-form-item label="选择团队">
              <J-select-multiple
                placeholder="请选择选择团队"
                :options="getTeamName"
                showId="id"
                v-model="queryParam.teamIds"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="单据编号" class="form-item">
              <j-input placeholder="请输入单据编号" v-model="queryParam.purchaseBill"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24" v-if="queryParam.permissionType != 3">
            <a-form-item label="申请部门" class="form-item">
              <j-select-depart placeholder="请选择申请部门" v-model="queryParam.proposerDeptId" />
            </a-form-item>
          </a-col>
          <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="申请人">
              <select-user-by-dep
                    placeholder="请选择申请人"
                    v-model="queryParam.proposer"/>
            </a-form-item>
          </a-col> -->
          <a-col :xl="6" :lg="7" :md="8" :sm="24" v-if="queryParam.permissionType != 4">
              <a-form-item label="费用所属团队" :wrapperCol="wrapperCol">
                <select-team-input placeholder="请选择团队" v-model="queryParam.teamId" :tdlx="3" :teamType="0"/>
              </a-form-item>
            </a-col>
          <!-- <template v-if="toggleSearchStatus"></template> -->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus" :disabled="isDisabledAuth('erpPurchaseApplyForm:add')">新增</a-button>
      <!-- <a-button type="primary" icon="download" @click="handleExportXls('采购申请单')" :disabled="isDisabledAuth('erpPurchaseApplyForm:export')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import" :disabled="isDisabledAuth('erpPurchaseApplyForm:import')">导入</a-button>
      </a-upload> -->
      <!-- 高级查询区域 -->
      <!--<j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel" :disabled="isDisabledAuth('erpPurchaseApplyForm:delete')"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item,index) in defColumns">
                <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                  <a-col :span="12" :key="index"><a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox></a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right;"><a-icon type="setting" :style='iconStyle'/></a>
      </a-popover>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x: '100%'}"
        :components="draggableComponent"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{getCheckboxProps:getCheckboxProps, selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        :customRow="customRow"
        @change="handleTableChange">
        <a slot="purchaseBill" slot-scope="text, record" @click="getDetail(record.id)">{{ text }}</a>
        <span slot="notify" slot-scope="text, record">
          <a-icon title="催办提醒" v-if="record.taskUrge" theme="twoTone" twoToneColor="#eb2f96"
                  @click="taskNotifyMe(flowCode,record.id)" type="notification"/>
          {{ text }}
        </span>
        <template slot="status" slot-scope="status">
           <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
            <template v-if="record.bpmStatus === '1'">
            <a-button
                    class="ruleButton"
                    :ghost="true"
                    type="primary"
                    icon="edit"
                    @click="handleEdit(record)"
                    :disabled="isDisabledAuth('erpPurchaseApplyForm:edit')"
            />
            <a-divider type="vertical"/>
            <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                <a-button
                        class="ruleButton"
                        :ghost="true"
                        type="primary"
                        icon="delete"
                        :disabled="isDisabledAuth('erpPurchaseApplyForm:delete')"/>
            </a-popconfirm>
            <!-- <a-divider type="vertical"/>
            <a-button type="primary" size="small" @click="beginProcess(record)" :disabled="isDisabledAuth('erpPurchaseApplyForm:startProcess')">发起流程</a-button> -->
        </template>
        <template v-else-if="showBtn(record.bpmStatus)&&queryParam.bizTaskType=='1'">
            <a-button type="primary" size="small" @click="handleProcess(record)">办理</a-button>
            <a-divider type="vertical"/>
        </template>
        <template v-else-if="queryParam.bizTaskType=='2' && showBtn(record.bpmStatus)">
            <a-button type="primary" size="small" @click="taskNotify(flowCode,record.id)">催办</a-button>
            <a-divider type="vertical"/>
            <a-popconfirm title="确定要作废吗?" @confirm="() => invalidProcess(record)">
                <a-button type="primary" size="small" :disabled="isDisabledAuth('erpPurchaseApplyForm:invalidProcess')">
                    作废流程
                </a-button>
            </a-popconfirm>
            <a-divider type="vertical"/>
        </template>
        <template v-if="record.bpmStatus !== '1'">
            <a-button type="primary" size="small" @click="handleTrack(record)" :disabled="isDisabledAuth('erpPurchaseApplyForm:viewTrack')">审批进度</a-button>
        </template>
        </span>

      </a-table>
    </div>

    <process-config-modal ref="processConfig" @ok="handleSuccess" @close="handleClose"></process-config-modal>
    <erp-purchase-apply-form-modal ref="modalForm" @ok="modalFormOk"></erp-purchase-apply-form-modal>
    <bpm-biz-task-deal-modal ref="taskDealModal" :path="path" :formData="formData" @ok="handleOk"></bpm-biz-task-deal-modal>
    <bpm-process-track-modal ref="bpmProcessTrackModal"></bpm-process-track-modal>
    <biz-task-notify-modal ref="taskNotifyModal"></biz-task-notify-modal>
    <biz-task-notify-me-modal ref="taskNotifyMeModal"></biz-task-notify-me-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import {JeecgBpmListMixin} from '@/mixins/JeecgBpmListMixin'
  import BpmBizTaskDealModal from "@/views/modules/bpmbiz/common/BpmBizTaskDealModal.vue";
  import BpmProcessTrackModal from "@/views/modules/bpmbiz/common/BpmProcessTrackModal.vue";
  import BizTaskNotifyModal from "@/views/modules/bpmbiz/common/BizTaskNotifyModal.vue";
  import BizTaskNotifyMeModal from "@/views/modules/bpmbiz/common/BizTaskNotifyMeModal.vue";
  import ErpPurchaseApplyFormModal from './modules/ErpPurchaseApplyFormModal'
  import {DisabledAuthFilterMixin} from '@/mixins/DisabledAuthFilterMixin'
  import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
  import SelectTeamInput from '@/views/scy/components/SelectTeamInput'
  import ProcessConfigModal from '@/views/scy/components/ProcessConfigModal'

  export default {
    name: 'ErpPurchaseApplyFormList',
    mixins:[JeecgBpmListMixin, mixinDevice, DisabledAuthFilterMixin],
    components: {
      ErpPurchaseApplyFormModal,
      BpmBizTaskDealModal,
      BpmProcessTrackModal,
      BizTaskNotifyModal,
      BizTaskNotifyMeModal,
      SelectUserByDep,
      SelectTeamInput,
      ProcessConfigModal
    },
    data () {
      return {
        description: '采购申请单管理页面',
        //表头
        columns:[],
        //列设置
        settingColumns:[],
        // 列定义
        defColumns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'单据编号',
            align:"center",
            width:200,
            dataIndex: 'purchaseBill',
            scopedSlots: { customRender: 'purchaseBill' },
            ellipsis: true,
          },
          {
            title:'申请人',
            align:"center",
            width:100,
            dataIndex: 'proposer_dictText',
            ellipsis: true,
          },
          {
            title:'申请部门',
            align:"center",
            width:200,
            dataIndex: 'proposerDeptId_dictText',
            ellipsis: true,
          },
          {
            title:'费用所属团队',
            width:200,
            align:"center",
            dataIndex: 'teamId_dictText',
            ellipsis: true,
          },
          {
            title:'期望到货时间',
            align:"center",
            width:200,
            dataIndex: 'expectUseTime',
            ellipsis: true,
          },
          {
            title:'采购事由',
            align:"center",
            width:200,
            dataIndex: 'purchaseReason',
            ellipsis: true,
          },
          // {
          //   title:'是否紧急',
          //   align:"center",
          //   dataIndex: 'isUrgency_dictText',
          //   ellipsis: true,
          // },
          {
            title:'审批状态',
            align:"center",
            width:200,
            dataIndex: 'bpmStatus_dictText',
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:200,
            scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action' }
          }
        ],
        url: {
          list: "/api/erp/purchase/procurement/erpPurchaseApplyForm/list",
          delete: "/api/erp/purchase/procurement/erpPurchaseApplyForm/delete",
          deleteBatch: "/api/erp/purchase/procurement/erpPurchaseApplyForm/deleteBatch",
          exportXlsUrl: "/api/erp/purchase/procurement/erpPurchaseApplyForm/exportXls",
          importExcelUrl: "api/erp/purchase/procurement/erpPurchaseApplyForm/importExcel",
          bizCount: "/api/erp/purchase/procurement/erpPurchaseApplyForm/bizCount",
        },
        //代码生成后需手动设置流程编码
        // flowCode: 'onl_erp_purchase_apply_form',
        flowCode: 'dev_erp_purchase_apply_form_001',
        formUrl: "/erp/purchase/procurement/modules/ErpPurchaseApplyFormForm",
        beanName: 'erpPurchaseApplyFormServiceImpl',
        processId: '1560089400301527041',
        formUrlMobile: "/pages/synergy/erpPurchaseApplyFormList",
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      handleSuccess(){
        this.loadData();
        this.$refs.modalForm.handleCancel()
        this.onClearSelected();
      },
      beginProcess(record){
        this.$refs.processConfig.visible = true
        this.$refs.processConfig.formUrl = this.formUrl
        this.$refs.processConfig.formUrlMobile = this.formUrlMobile
        this.$refs.processConfig.flowCode = this.flowCode
        this.$refs.processConfig.edit(record, this.processId, this.beanName)
      },
      //流程审批结束禁用
      getCheckboxProps(record) {
        return {
          props: {
            disabled: record.bpmStatus !== "1"
          }
        }
      },
      //查看详情
      getDetail(id) {
        this.$router.push({
          path: `/erp/purchase/procurement/ErpPurchaseApplyFormListDetail/${id}`,
        })
      },
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'purchaseBill',text:'采购单号',dictCode:''})
        fieldList.push({type:'sel_depart',value:'applicant',text:'申请单位'})
        fieldList.push({type:'sel_depart',value:'teamId',text:'费用所属团队'})
        fieldList.push({type:'date',value:'expectUseTime',text:'预计使用时间'})
        fieldList.push({type:'string',value:'provisionBroad',text:'采购大类',dictCode:''})
        fieldList.push({type:'string',value:'projectId',text:'关联项目',dictCode:''})
        fieldList.push({type:'Text',value:'purchaseReason',text:'采购事由',dictCode:''})
        fieldList.push({type:'Text',value:'remark',text:'备注',dictCode:''})
        fieldList.push({type:'string',value:'purchaseFile',text:'附件信息',dictCode:''})
        fieldList.push({type:'string',value:'bpmStatus',text:'审批状态',dictCode:''})
        fieldList.push({type:'int',value:'checkStatus',text:'流程审批结果',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
